package com.villaday.idf.adapter3;


import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model.MaterialRecommendEntity;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;


public class InviteZQAdapter extends AbsRecyclerViewAdapter<MaterialRecommendEntity.BodyEntity.DataListEntity.ImageListEntity> {


    public InviteZQAdapter(Context context) {
        super(context, R.layout.item_img);


    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, MaterialRecommendEntity.BodyEntity.DataListEntity.ImageListEntity d, final int position) {
        final ImageView img = (ImageView) holder.getView(R.id.img);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogeUtil.e("111","555");

            }
        });
        final RequestOptions options = new RequestOptions()
                .error(R.drawable.ic_replace_0)
                .fitCenter()
                .placeholder(R.drawable.ic_replace_0);
       /* Glide.with(context).load(d.getImageUrl())
                .apply(options)
                .into((ImageView) holder.getView(R.id.img));*/
        Glide.with(context).asBitmap().apply(options).load(d.getImageUrl()).into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {


                img.getLayoutParams().height = PhoneUtil.dp2px(context, 240);
                img.getLayoutParams().width = PhoneUtil.dp2px(context, 164);

                img.requestLayout();
                img.setImageBitmap(resource);
                img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       /* if (mCallback != null) {
                            List<ImageView> imgs = new ArrayList<>();
                            imgs.add(img);

                            List<String> url = new ArrayList<>();
                            url.add(d.getPoster());
                            mCallback.onThumbPictureClick((ImageView) v, imgs, url);
                        }*/
                    }
                });
            }
        });


    }
}
